package com.zhiyou100.review.day019.homework;

/**
 * @packageName: Homework5
 * @className: com.zhiyou100.review.day019.homework
 * @Description: TODO 作业 5 写一个程序  打印前20个  裴波纳契数列的值： 裴波纳契数列： 1  1  2  3  5  8 13 21 34
 * @author: yang
 * @date: 6/30/20
 */
public class Homework5 {
    public static void main(String[] args) {
        int max = 20;
        for (int i = 1; i <= max; i++) {
            System.out.println(fibonacciSequence(i));
        }

    }

    /**
     * @Description: TODO F[n]=F[n-1]+F[n-2](n>=3,F[1]=1,F[2]=1)   F(n)=F(n-1)+F(n-2)
     * @name: fibonacciSequence
     * @param: []
     * @return: int
     * @date: 6/30/20 23:30
     * @author: yang
     */
    private static int fibonacciSequence(int i) {

        int one = 1;
        int two = 3;

        if (i < one) {
            return 0;
        } else if (i < two) {
            return 1;
        } else {
            return fibonacciSequence(i - 1) + fibonacciSequence(i - 2);
        }
    }
}

